﻿using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.List.PlugIn.Args;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace Jac.XkDemo.BOS.Business.PlugIn
{
    /// <summary>
    /// 列表插件
    /// </summary>
    [Description("【列表插件】干预列表查询结果"), HotUpdate]
    public class AddListQueryFilterStringListPlugIn : AbstractListPlugIn
    {

        /// <summary>
        /// 重写列表过滤，干预列表查询结果
        /// </summary>
        public override void PrepareFilterParameter(FilterArgs e)
        {
            base.PrepareFilterParameter(e);

            e.FilterString = e.FilterString.JoinFilterString("FBillNo Like 'CG%'");
            e.FilterString = e.FilterString.JoinFilterString("FPOOrderEntry_FEntryID NOT IN (1,2,3)");

            // 设置列表排序           
            e.SortString = e.FilterString.JoinFilterString("FDate DESC,FDocumentStatus");

            // 采购订单列表始终不显示单据编号列和采购日期列           
            var needHideColumns = new HashSet<string>(new[] { "FBillNo", "FDate" }, StringComparer.OrdinalIgnoreCase);
            // 方案1：直接移除列            
            e.ColumnFields.RemoveAll(o => needHideColumns.Contains(o.FieldName));

            // 方案2：不移除列，仅将列设置为隐藏           
            foreach (var columnField in e.ColumnFields)
            {
                if (needHideColumns.Contains(columnField.FieldName))
                {
                    columnField.Visible = false;
                }
            }


        }
    }
}
